//
//  WmcResolution.swift
//  YPWatermarkCamera
//
//  Created by Json on 2023/7/12.
//

import UIKit
import YPGraphicEngine
import AVFoundation

class WmcResolution: WmcBaseModel {
    
    enum Level: Int {
        /// 低清
        case low = 1
        /// 普清
        case common
        /// 标清
        case standard
        /// 高清
        case high
        
        var name: String {
            switch self {
            case .low:
                return "低清"
            case .common:
                return "普清"
            case .standard:
                return "标清"
            case .high:
                return "高清"
            }
        }
        var defaultHeight: Int {
            switch self {
            case .low:
                return 640
            case .common:
                return 1600
            case .standard:
                return 2560
            case .high:
                return 4160
            }
        }
        
        /// 对应的相机分辨率设置
        var preset: AVCaptureSession.Preset {
            switch self {
            case .low:
                return .vga640x480
            case .common:
                return .hd1920x1080
            case .standard:
                return .hd4K3840x2160
            case .high:
                return .hd4K3840x2160
            }
        }
    }
    /// 分辨率等级
    var level: Level = .low
    /// 分辨率宽度
    var width: Int = 0
    /// 分辨率高度
    var height: Int = 0
    /// 图片内存大小
    var memorySize: String = ""
    
    // MARK: Init
    init(level: Level, width: Int, height: Int) {
        self.level = level
        self.width = width
        self.height = height
        super.init()
    }
    
    convenience init(level: Level, aspectRatio: AspectRatio) {
        let width = (level.defaultHeight.yp.cgFloat / aspectRatio.ratioHW).yp.int
        self.init(level: level, width: width, height: level.defaultHeight)
        switch level {
        case .low:
            self.memorySize = "100K"
        case .common:
            self.memorySize = "400KB"
        case .standard:
            self.memorySize = "1MB"
        case .high:
            self.memorySize = "4MB"
        }
    }
    
    required init() {}
}

extension WmcResolution {
    typealias AspectRatio = YPGESunglasses.AspectRatio
}
